﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;

namespace IpSelector
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            while (i++ < 5)
            {
                DnsHelper.TestAccessbility();
                WaitHandle.WaitAny(new WaitHandle[] { DnsHelper.waitHandle });
                Thread.Sleep(60000*5);
            }

            List<DnsItem> its = DnsHelper.GoogleHost.FindAll((item) => item.UnAvailable == 0 && item.Available > 0);
            its.Sort((a, b) => a.Delay.CompareTo(b.Delay));

            StringBuilder stringBuilder=new StringBuilder();
            foreach (DnsItem dnsItem in its)
            {
                stringBuilder.Append(dnsItem.Address + ",");
            }
            File.WriteAllText("a.txt", stringBuilder.ToString());
        }
    }
}
